<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Aes</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Aes</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/lib/ruby-aes_rb.html">
                lib/ruby-aes.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000005">bs</a>&nbsp;&nbsp;
      <a href="#M000006">bs=</a>&nbsp;&nbsp;
      <a href="#M000008">check_iv</a>&nbsp;&nbsp;
      <a href="#M000007">check_key</a>&nbsp;&nbsp;
      <a href="#M000010">check_kl</a>&nbsp;&nbsp;
      <a href="#M000009">check_mode</a>&nbsp;&nbsp;
      <a href="#M000013">decrypt_block</a>&nbsp;&nbsp;
      <a href="#M000015">decrypt_buffer</a>&nbsp;&nbsp;
      <a href="#M000017">decrypt_stream</a>&nbsp;&nbsp;
      <a href="#M000012">encrypt_block</a>&nbsp;&nbsp;
      <a href="#M000014">encrypt_buffer</a>&nbsp;&nbsp;
      <a href="#M000016">encrypt_stream</a>&nbsp;&nbsp;
      <a href="#M000011">init</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000005" class="method-detail">
        <a name="M000005"></a>

        <div class="method-heading">
          <a href="#M000005" class="method-signature">
          <span class="method-name">bs</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000005-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 45</span>
45:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">bs</span>(); <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@@bs</span> <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000006" class="method-detail">
        <a name="M000006"></a>

        <div class="method-heading">
          <a href="#M000006" class="method-signature">
          <span class="method-name">bs=</span><span class="method-args">(bs)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000006-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 46</span>
46:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">bs=</span>(<span class="ruby-identifier">bs</span>); <span class="ruby-ivar">@@bs</span> = <span class="ruby-identifier">bs</span>.<span class="ruby-identifier">to_i</span>; <span class="ruby-ivar">@@bs</span><span class="ruby-operator">==</span><span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-value">4096</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@@bs</span> = <span class="ruby-ivar">@@bs</span> <span class="ruby-operator">-</span> <span class="ruby-ivar">@@bs</span><span class="ruby-operator">%</span><span class="ruby-value">16</span> <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000008" class="method-detail">
        <a name="M000008"></a>

        <div class="method-heading">
          <a href="#M000008" class="method-signature">
          <span class="method-name">check_iv</span><span class="method-args">(iv_string)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000008-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 61</span>
61:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_iv</span>(<span class="ruby-identifier">iv_string</span>)
62:         <span class="ruby-identifier">k</span> = <span class="ruby-identifier">iv_string</span>.<span class="ruby-identifier">length</span>
63:         <span class="ruby-identifier">hex</span> = (<span class="ruby-identifier">iv_string</span> <span class="ruby-operator">=~</span> <span class="ruby-node">/[a-f0-9A-F]{#{k}}/</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
64:         <span class="ruby-identifier">bin</span> = <span class="ruby-operator">!</span> <span class="ruby-identifier">hex</span>
65:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-value">32</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">hex</span>
66:             <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">iv_string</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">&quot;H*&quot;</span>)
67:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">bin</span>
68:             <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">iv_string</span>
69:         <span class="ruby-keyword kw">else</span>
70:             <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad IV string&quot;</span>
71:         <span class="ruby-keyword kw">end</span>
72:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000007" class="method-detail">
        <a name="M000007"></a>

        <div class="method-heading">
          <a href="#M000007" class="method-signature">
          <span class="method-name">check_key</span><span class="method-args">(key_string, kl = 128)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000007-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 48</span>
48:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_key</span>(<span class="ruby-identifier">key_string</span>, <span class="ruby-identifier">kl</span> = <span class="ruby-value">128</span>)
49:         <span class="ruby-identifier">kl</span> = <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_kl</span>(<span class="ruby-identifier">kl</span>)
50:         <span class="ruby-identifier">k</span> = <span class="ruby-identifier">key_string</span> <span class="ruby-value">? </span><span class="ruby-identifier">key_string</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">:</span> <span class="ruby-value">0</span>
51:         <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad key string or bad key length&quot;</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">k</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">kl</span><span class="ruby-operator">/</span><span class="ruby-value">8</span>) <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">k</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">kl</span><span class="ruby-operator">/</span><span class="ruby-value">4</span>)
52:         <span class="ruby-identifier">hex</span> = (<span class="ruby-identifier">key_string</span> <span class="ruby-operator">=~</span> <span class="ruby-node">/[a-f0-9A-F]{#{k}}/</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">kl</span><span class="ruby-operator">/</span><span class="ruby-value">4</span>)
53:         <span class="ruby-identifier">bin</span> = <span class="ruby-operator">!</span> <span class="ruby-identifier">hex</span>
54:         <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span> (([<span class="ruby-value">32</span>, <span class="ruby-value">48</span>, <span class="ruby-value">64</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">k</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">hex</span>) <span class="ruby-operator">||</span>
55:            ([<span class="ruby-value">16</span>, <span class="ruby-value">24</span>, <span class="ruby-value">32</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">k</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">bin</span>))
56:             <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad key string&quot;</span>
57:         <span class="ruby-keyword kw">end</span>
58:         <span class="ruby-identifier">hex</span> <span class="ruby-value">? </span>[<span class="ruby-identifier">key_string</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">&quot;H*&quot;</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">key_string</span>
59:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000010" class="method-detail">
        <a name="M000010"></a>

        <div class="method-heading">
          <a href="#M000010" class="method-signature">
          <span class="method-name">check_kl</span><span class="method-args">(key_length)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000010-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 82</span>
82:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_kl</span>(<span class="ruby-identifier">key_length</span>)
83:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">key_length</span>
84:         <span class="ruby-keyword kw">when</span> <span class="ruby-value">128</span>, <span class="ruby-value">192</span>, <span class="ruby-value">256</span>
85:         <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad key length&quot;</span>
86:         <span class="ruby-keyword kw">end</span>
87:         <span class="ruby-identifier">key_length</span>
88:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000009" class="method-detail">
        <a name="M000009"></a>

        <div class="method-heading">
          <a href="#M000009" class="method-signature">
          <span class="method-name">check_mode</span><span class="method-args">(mode)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000009-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 74</span>
74:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_mode</span> (<span class="ruby-identifier">mode</span>)
75:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">mode</span>
76:         <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'ECB'</span>, <span class="ruby-value str">'CBC'</span>, <span class="ruby-value str">'OFB'</span>, <span class="ruby-value str">'CFB'</span>
77:         <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad cipher mode&quot;</span>
78:         <span class="ruby-keyword kw">end</span>
79:         <span class="ruby-identifier">mode</span>
80:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000013" class="method-detail">
        <a name="M000013"></a>

        <div class="method-heading">
          <a href="#M000013" class="method-signature">
          <span class="method-name">decrypt_block</span><span class="method-args">(keyl, mode, key, iv, block = &quot;DEFAULT PLAINTXT&quot;)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000013-source">
<pre>
     <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 106</span>
106:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">decrypt_block</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>, <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;DEFAULT PLAINTXT&quot;</span>)
107:         <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">init</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>)
108:         <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">decrypt_block</span>(<span class="ruby-identifier">block</span>)
109:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000015" class="method-detail">
        <a name="M000015"></a>

        <div class="method-heading">
          <a href="#M000015" class="method-signature">
          <span class="method-name">decrypt_buffer</span><span class="method-args">(keyl, mode, key, iv, buffer = &quot;DEFAULT PLAINTXT&quot;)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000015-source">
<pre>
     <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 116</span>
116:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">decrypt_buffer</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>, <span class="ruby-identifier">buffer</span> = <span class="ruby-value str">&quot;DEFAULT PLAINTXT&quot;</span>)
117:         <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad Block size&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">16</span>
118:         <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">init</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>)
119:         <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">decrypt_buffer</span>(<span class="ruby-identifier">buffer</span>)
120:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000017" class="method-detail">
        <a name="M000017"></a>

        <div class="method-heading">
          <a href="#M000017" class="method-signature">
          <span class="method-name">decrypt_stream</span><span class="method-args">(keyl, mode, key, iv, sin = STDIN, sout = STDOUT)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000017-source">
<pre>
     <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 145</span>
145:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">decrypt_stream</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>, <span class="ruby-identifier">sin</span> = <span class="ruby-constant">STDIN</span>, <span class="ruby-identifier">sout</span> = <span class="ruby-constant">STDOUT</span>)
146:         <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">init</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>)
147:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">sout</span>
148:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>, <span class="ruby-constant">Array</span>, <span class="ruby-constant">IO</span>
149:         <span class="ruby-keyword kw">else</span>
150:             <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad output stream (String, Array, IO)&quot;</span>
151:         <span class="ruby-keyword kw">end</span>
152:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">sin</span>
153:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>
154:             <span class="ruby-identifier">sout</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">decrypt_buffer</span>(<span class="ruby-identifier">sin</span>)
155:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">IO</span>
156:             <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">buf</span> = <span class="ruby-identifier">sin</span>.<span class="ruby-identifier">read</span>(<span class="ruby-ivar">@@bs</span>)<span class="ruby-comment cmt">#+1)</span>
157:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@@bs</span>
158:                 <span class="ruby-identifier">sout</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">decrypt_blocks</span>(<span class="ruby-identifier">buf</span>)
159:               <span class="ruby-keyword kw">else</span>
160:                 <span class="ruby-identifier">sout</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">decrypt_buffer</span>(<span class="ruby-identifier">buf</span>)
161:               <span class="ruby-keyword kw">end</span>
162:             <span class="ruby-keyword kw">end</span>
163:         <span class="ruby-keyword kw">else</span>
164:             <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad input stream (String, IO)&quot;</span>
165:         <span class="ruby-keyword kw">end</span>
166:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000012" class="method-detail">
        <a name="M000012"></a>

        <div class="method-heading">
          <a href="#M000012" class="method-signature">
          <span class="method-name">encrypt_block</span><span class="method-args">(keyl, mode, key, iv, block = &quot;DEFAULT PLAINTXT&quot;)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000012-source">
<pre>
     <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 100</span>
100:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>, <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;DEFAULT PLAINTXT&quot;</span>)
101:         <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad Block size&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">16</span>
102:         <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">init</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>)
103:         <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span>)
104:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000014" class="method-detail">
        <a name="M000014"></a>

        <div class="method-heading">
          <a href="#M000014" class="method-signature">
          <span class="method-name">encrypt_buffer</span><span class="method-args">(keyl, mode, key, iv, buffer = &quot;PLAINTEXT&quot;)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000014-source">
<pre>
     <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 111</span>
111:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">encrypt_buffer</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>, <span class="ruby-identifier">buffer</span> = <span class="ruby-value str">&quot;PLAINTEXT&quot;</span>)
112:         <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">init</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>)
113:         <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">encrypt_buffer</span>(<span class="ruby-identifier">buffer</span>)
114:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000016" class="method-detail">
        <a name="M000016"></a>

        <div class="method-heading">
          <a href="#M000016" class="method-signature">
          <span class="method-name">encrypt_stream</span><span class="method-args">(keyl, mode, key, iv, sin = STDIN, sout = STDOUT)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000016-source">
<pre>
     <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 122</span>
122:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">encrypt_stream</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>, <span class="ruby-identifier">sin</span> = <span class="ruby-constant">STDIN</span>, <span class="ruby-identifier">sout</span> = <span class="ruby-constant">STDOUT</span>)
123:         <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">init</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>)
124:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">sout</span>
125:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>, <span class="ruby-constant">Array</span>, <span class="ruby-constant">IO</span>
126:         <span class="ruby-keyword kw">else</span>
127:             <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad output stream (String, Array, IO)&quot;</span>
128:         <span class="ruby-keyword kw">end</span>
129:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">sin</span>
130:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>
131:             <span class="ruby-identifier">sout</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">encrypt_buffer</span>(<span class="ruby-identifier">sin</span>)
132:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">IO</span>
133:             <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">buf</span> = <span class="ruby-identifier">sin</span>.<span class="ruby-identifier">read</span>(<span class="ruby-ivar">@@bs</span>)
134:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@@bs</span>
135:                 <span class="ruby-identifier">sout</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">encrypt_blocks</span>(<span class="ruby-identifier">buf</span>)
136:               <span class="ruby-keyword kw">else</span>
137:                 <span class="ruby-identifier">sout</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">encrypt_buffer</span>(<span class="ruby-identifier">buf</span>)
138:               <span class="ruby-keyword kw">end</span>
139:             <span class="ruby-keyword kw">end</span>
140:         <span class="ruby-keyword kw">else</span>
141:             <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad input stream (String, IO)&quot;</span>
142:         <span class="ruby-keyword kw">end</span>
143:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000011" class="method-detail">
        <a name="M000011"></a>

        <div class="method-heading">
          <a href="#M000011" class="method-signature">
          <span class="method-name">init</span><span class="method-args">(keyl, mode, key, iv)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000011-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ruby-aes.rb, line 90</span>
90:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">init</span>(<span class="ruby-identifier">keyl</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>)
91:         <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@@aes</span>
92:             <span class="ruby-ivar">@@aes</span> = <span class="ruby-constant">AesAlg</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_kl</span>(<span class="ruby-identifier">keyl</span>), <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_mode</span>(<span class="ruby-identifier">mode</span>),
93:                                <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_key</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">keyl</span>), <span class="ruby-identifier">iv</span> <span class="ruby-value">? </span><span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_iv</span>(<span class="ruby-identifier">iv</span>) <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>)
94:         <span class="ruby-keyword kw">else</span>
95:             <span class="ruby-ivar">@@aes</span>.<span class="ruby-identifier">init</span>(<span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_kl</span>(<span class="ruby-identifier">keyl</span>), <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_mode</span>(<span class="ruby-identifier">mode</span>),
96:                        <span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_key</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">keyl</span>), <span class="ruby-identifier">iv</span> <span class="ruby-value">? </span><span class="ruby-constant">Aes</span>.<span class="ruby-identifier">check_iv</span>(<span class="ruby-identifier">iv</span>) <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>)
97:         <span class="ruby-keyword kw">end</span>
98:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>